package libs.yzx.zaza;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import java.util.ArrayList;

import libs.yzx.zaza.za.IMyAidlInterface;
import libs.yzx.zaza.za.RemoteService;

/**
 * Created by Administrator on 2016/8/6.
 */
public class AIDLActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        bindService(new Intent(this, RemoteService.class), new ServiceConnection() {
            public void onServiceConnected(ComponentName name, IBinder service) {
                IMyAidlInterface inter = IMyAidlInterface.Stub.asInterface(service);
                try {
                    ArrayList<String> out = new ArrayList<>();
                    String result = inter.getString(7, out);
                    Toast.makeText(AIDLActivity.this, result + "  " + out.get(0), Toast.LENGTH_SHORT).show();
                } catch (RemoteException e) {
                    Toast.makeText(AIDLActivity.this, "bind error", Toast.LENGTH_SHORT).show();
                }
            }

            public void onServiceDisconnected(ComponentName name) {

            }
        }, BIND_AUTO_CREATE);

    }

}
